﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="TaskList.aspx.cs" Inherits="TireService.Web.View.ServiceView.TaskList" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPivotGrid" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxSplitter" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<%@ Register src="../../UserControls/Tasks/ucEditTask.ascx" tagname="ucEditTask" tagprefix="uc1" %>
<%@ Register src="../../UserControls/Tasks/ucTaskHistory.ascx" tagname="ucTaskHistory" tagprefix="uc2" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgTaskList" alt="" src="~/Images/Medium/stopwatch.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblTaskList" runat="server" Text="Kunde opgaver"></asp:Label></h3>
            </td>
        </tr>
    </table>

    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dx:ASPxButton>
            </td>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dx:ListEditItem Value="1" Text="Export xls" />
                        <dx:ListEditItem Value="2" Text="Export csv" />
                        <dx:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnExport" runat="server" Text="Exporter" OnClick="btnExport_Click" Width="75px" >
                </dx:ASPxButton>
            </td>
            <td align="right">
                <%--<asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:DropDownList ID="ddlView" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddlView_SelectedIndexChanged">
                    <asp:ListItem Value="0">Ingen gruppering</asp:ListItem>
                    <asp:ListItem Value="1">Grupper efter Mærke</asp:ListItem>
                </asp:DropDownList>
                &nbsp;
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>--%>
            </td>
        </tr>
    </table>
    <hr />

    <script type="text/javascript">

        function ContainerSelected(s, e) {
            // Check if tasktype and tasktype status is selected
            if (ddlTaskTypeStatus.GetValue() > 0) {
                // Perform callback update gridview with tasks
                UpdateTaskGridview(ddlContainer.GetValue(), ddlTaskType.GetValue(), ddlTaskTypeStatus.GetValue());
            }
        }

        // Function that runs when a task type has been selected - update tasktype status dropdownlist
        function TaskTypeSelected(s, e) {
            ddlTaskTypeStatus.PerformCallback(ddlTaskType.GetValue().toString());
        }

        // Function that runs when Tasktype status has been selected - refresh gridview with tasks
        function TaskTypeStatusSelected(s, e) {
            // Perform callback update gridview with tasks
            UpdateTaskGridview(ddlContainer.GetValue(), ddlTaskType.GetValue(), ddlTaskTypeStatus.GetValue());
        }

        // Function that perform callback to task gridview to update on client
        function UpdateTaskGridview(containerid, tasktypeid, tasktypestatusid) {
            var input = containerid + '|';
            input += tasktypeid + '|';
            input += tasktypestatusid;

            gvTask.PerformCallback(input);
        }

    </script>

    <!-- Javascript for implementation of edittask usercontrol -->
    <script type="text/javascript">
    
            // Functions for edit task modalpopup
            function ShowEditTaskModalPopup(element, key) {
                callbackEditTaskPanel.SetContentHtml("");
                pcEditTask.ShowAtElement(element);
                callbackEditTaskPanel.PerformCallback(key);
                EditTaskKeyValue = key;
            }

            function EditTaskCompleteRefreshParent() {
                //Perform action on parent control - ex. refresh gridview with PerformCallback
                UpdateTaskGridview(ddlContainer.GetValue(), ddlTaskType.GetValue(), ddlTaskTypeStatus.GetValue());
            }
    </script>

    <!-- Javascript for implementation of task history usercontrol -->
    <script type="text/javascript">

        // Functions for task history modalpopup
        function ShowTaskHistoryModalPopup(element, key) {
            callbackTaskHistoryPanel.SetContentHtml("");
            pcTaskHistory.ShowAtElement(element);
            callbackTaskHistoryPanel.PerformCallback(key);
            TaskHistoryKeyValue = key;
        }

    </script>

    <table>
        <tr>
            <td>
                <dx:ASPxComboBox ID="ddlContainer" ClientInstanceName="ddlContainer" runat="server">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { ContainerSelected() }" />
                </dx:ASPxComboBox>
            </td>
            <td>
                <dx:ASPxComboBox ID="ddlTaskType" ClientInstanceName="ddlTaskType" runat="server">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { TaskTypeSelected() }" />
                </dx:ASPxComboBox>
            </td>
            <td>
                <dx:ASPxComboBox ID="ddlTaskTypeStatus" ClientInstanceName="ddlTaskTypeStatus" runat="server" OnCallback="ddlTaskTypeStatus_Callback">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { TaskTypeStatusSelected() }" EndCallback="function(s, e) { TaskTypeStatusSelected() }" />
                </dx:ASPxComboBox> 
            </td>
        </tr>
    </table>

    <dx:ASPxGridView ID="gvTask" runat="server" ClientInstanceName="gvTask" Width="100%" 
        KeyFieldName="TaskId" AutoGenerateColumns="False" EnableCallBacks="True"
        OnCustomCallback="gvTask_CustomCallback">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="false" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} opgaver)" 
                Text="Side {0} af {1} ({2} opgaver)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne opgave?" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="true" AllowDragDrop="true" />
        <Columns>
            <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvTask.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataColumn Caption="Rediger" Width="106px" VisibleIndex="1">
                <DataItemTemplate>
                    <a href="javascript:void(0);" onclick="ShowEditTaskModalPopup(this, '<%# Container.KeyValue %>')"><img src="~/Images/Tiny/contract.png" id="img3" runat="server" alt="Opret opgave" /></a> | <a href="javascript:void(0);" onclick="ShowTaskHistoryModalPopup(this, '<%# Container.KeyValue %>')"><img src="~/Images/Tiny/history.png" id="img1" runat="server" alt="Vis historik" /></a>
                </DataItemTemplate>
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TaskId" VisibleIndex="1" Caption="Opgavenr">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TaskTypeId" VisibleIndex="1" Visible="false" Caption="TaskTypeId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TaskTypeDescription" VisibleIndex="1" Caption="Type">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TaskTypeStatusId" VisibleIndex="1" Visible="false" Caption="TaskTypeStatusId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TaskTypeStatusDescription" VisibleIndex="1" Caption="Status">
            </dx:GridViewDataColumn>
            <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="1" Caption="Kundenr">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId">
                </PropertiesHyperLinkEdit>
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="1" Caption="Regnr.">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ContainerId" VisibleIndex="1" Visible="false" Caption="ContainerId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ContainerNumber" VisibleIndex="1" Caption="Lager">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Createdate" VisibleIndex="1" Caption="Oprettet">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CompletionDate" VisibleIndex="1" Caption="Afsluttet">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn>
                <DataItemTemplate>
                    <dx:ASPxLabel ID="lblTaskDetail" runat="server" Text='<%# GetTaskDetailCount(Convert.ToInt32(Container.KeyValue)) %>'>
                    </dx:ASPxLabel>
                </DataItemTemplate>
            </dx:GridViewDataColumn>
        </Columns>                                            
        <Templates>
            <DetailRow>
                Opgavedetaljer
                <br />
                <dx:ASPxGridView ID="gvTaskDetail" ClientInstanceName="gvTaskDetail" runat="server" KeyFieldName="TaskDetailId"
                    Width="100%" OnBeforePerformDataSelect="gvTaskDetail_DataSelect">
                    <Columns>
                        <dx:GridViewDataColumn FieldName="TaskDetailId" Caption="Id" VisibleIndex="1" />
                        <dx:GridViewDataColumn FieldName="TaskDetailTypeId" Caption="Type" Visible="false" VisibleIndex="2" />
                        <dx:GridViewDataColumn FieldName="Description" Caption="Beskrivelse" VisibleIndex="2" />
                        <dx:GridViewDataColumn FieldName="EstimatedTime" Caption="Estimeret tid" VisibleIndex="2" />
                        <dx:GridViewDataColumn FieldName="Amount" Caption="Antal" VisibleIndex="3" />
                        <dx:GridViewDataColumn FieldName="NoteToEmployee" Caption="Note" VisibleIndex="4" />
                        <dx:GridViewDataColumn FieldName="Completed" Caption="Afsluttet" VisibleIndex="5" />
                        <dx:GridViewDataColumn FieldName="Cancelled" Caption="Annulleret" VisibleIndex="6" />
                    </Columns>
                </dx:ASPxGridView>
            </DetailRow>
        </Templates>
        <SettingsDetail ShowDetailRow="true" AllowOnlyOneMasterRowExpanded="true" />   
    </dx:ASPxGridView>

    <dx:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvTask">
    </dx:ASPxGridViewExporter>

    <uc1:ucEditTask ID="ucEditTask" runat="server" />
    <uc2:ucTaskHistory ID="ucTaskHistory" runat="server" />

    
</asp:Content>
